home *** CD-ROM | disk | FTP | other *** search
- Path: news.spies.com!usenet
- From: Erik Max Francis <max@alcyone.com>
- Newsgroups: comp.lang.c,comp.unix.programmer,comp.unix.questions
- Subject: Re: Correct usage of system call?
- Date: Thu, 28 Mar 1996 19:56:16 -0800
- Organization: Alcyone Systems
- Message-ID: <315B5F60.6CEE6525@alcyone.com>
- References: <4jb03v$oi6@news.tamu.edu>
- NNTP-Posting-Host: newton.alcyone.com
- Mime-Version: 1.0
- Content-Type: text/plain; charset=us-ascii
- Content-Transfer-Encoding: 7bit
- X-Mailer: Mozilla 2.01 (X11; I; Linux 1.2.13 i486)
-
- Justin Ray Mcelhanon wrote:
-
- > It works great, however, I'd like to add in a command to allow one to
- > type in the site name. Example, when you call up the ftp case it does
- > a scanf(%s,site); (with site declared as an char string) anyway I then
- > want to take that and put it in the system command. ie system("ftp site"),
- > but that is not the proper syntax, how could I accomplish this?
-
- Only the printf family takes the formatted arguments that you're trying to use
- (that's what the trailing `f' is for). What you need to do is build a string
- for the system call and then execute system with that built string.
-
- You can do this in two easy ways. Assume that you have an array of chars s
- which contains enough space to hold your string (you have to ensure this
- yourself), and site is the user input string that has been properly read in.
- You can then
-
- strcpy(s, "ftp ");
- strcat(s, site);
- system(s);
-
- or if you're lazy
-
- sprintf(s, "ftp %s", site);
- system(s);
-
- Note that s has to be a different array of char than site, or you will have
- problems. If you're not familiar with what calls such as strcpy, strcat, and
- sprintf do, then check your reference manuals.
-
- This is part of the natural learning curve involved in using C: You come to
- realize that you are given the power (and responsibility!) of doing whatever
- you like.
-
- --
- Erik Max Francis &tSftDotIotE && http://www.alcyone.com/max && max@alcyone.com
- San Jose, California, U.S.A. && 37 20 07 N 121 53 38 W && the 4th R is respect
- H.3`S,3,P,3$S,#$Q,C`Q,3,P,3$S,#$Q,3`Q,3,P,C$Q,#(Q.#`-"C`- && 1love && folasade
- Omnia quia sunt, lumina sunt. && Dominion, GIGO, GOOGOL, Omega, Psi, Strategem
- "Out from his breast/his soul went to seek/the doom of the just." -- _Beowulf_
-